package com.czk.model.observe.practice;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/6/7 10:15
 */
public class WeChatSubject implements Subject {
    List<Observer> observers = new ArrayList<>(10);

    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers(String message) {
        // 遍历
        for (Observer observer : observers) {
            observer.task(message);
        }
    }
}
